package com.yanqu.road.server.logic.activity.condition.beautylottery;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.args.ConditionTypeValueArgs;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseNewRankActivityCondition;

import java.math.BigInteger;

public class PeerlessBeautyLotteryRankCondition extends BaseNewRankActivityCondition {

    public PeerlessBeautyLotteryRankCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        ConditionTypeValueArgs args = (ConditionTypeValueArgs) object;
        if (args.getType() != baseActivityData.getActivityId()) {
            return;
        }
        BigInteger score = getValue().add(BigInteger.valueOf(args.getValue()));
        if (!score.equals(getValue())) {
            setValue(score);
            rankChange();
        }
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.PeerlessBeautyLotteryRank.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.PeerlessBeautyLotteryRank.getValue(), handle);
    }
}
